from django.db import models

# Create your models here.

#用户新信息表
class UserInfo(models.Model):

    username = models.CharField(max_length=32,verbose_name='用户名',unique=True)
    password = models.CharField(max_length=32, verbose_name='密码')

    phone = models.CharField(max_length=32,verbose_name='手机号', unique=True)
    email = models.EmailField(max_length=32,verbose_name='邮箱',unique=True)


# 价格策略
class PircePolicy(models.Model):

    category_choices = (
        (1, '免费版'),
        (2, 'vip'),
        (3, 'svip'),
    )

    catogory = models.SmallIntegerField(choices=category_choices,default=1,verbose_name='收费类型')
    title = models.CharField(verbose_name='标题', max_length=64, null=True, blank=True)
    price = models.PositiveIntegerField(verbose_name='价格')  # 正整数

    project_num = models.PositiveIntegerField(verbose_name='项目数量')
    project_member = models.PositiveIntegerField(verbose_name='项目成员人数')
    project_space = models.PositiveIntegerField(verbose_name='每个项目空间', help_text='单位是M')
    per_file_size = models.PositiveIntegerField(verbose_name='单文件大小', help_text='单位是M')


# 购买记录
class Transaction(models.Model):
    status_choices = (
        (1,'未支付'),
        (2,'已支付'),
    )
    status = models.SmallIntegerField(choices=status_choices,verbose_name='状态')
    order = models.CharField(verbose_name='订单号',max_length=64,unique=True)
    user = models.ForeignKey('UserInfo', verbose_name='用户')
    price_policy = models.ForeignKey('PircePolicy', verbose_name='价格策略')
    # forms.CharField(help_text='提示文本')
    count = models.IntegerField(verbose_name='数量(年)', help_text='0表示无限期')

    price = models.IntegerField(verbose_name='实际支付价格')

    start_datetime = models.DateTimeField(verbose_name='开始时间',null=True, blank=True)  # required:False
    end_datetime = models.DateTimeField(verbose_name='结束时间',null=True, blank=True)

    create_datetime = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)



# 项目表
class Project(models.Model):
    color_choices = (
        (1, "#00F5FF"),
        (2, "#FFE4B5"),
        (3, "#FFE4E1"),
        (4, "#54FF9F"),
        (5, "#00BFFF"),
        (6, "#FF6A6A"),
        (7, "#FF00FF"),
    )

    name = models.CharField(verbose_name='项目名称', max_length=32,)
    color = models.SmallIntegerField(choices=color_choices,verbose_name='颜色', default=1)

    desc = models.CharField(verbose_name='项目描述',max_length=64, null=True, blank=True)
    use_space = models.IntegerField(verbose_name='项目已用空间', default=0)
    star = models.BooleanField(verbose_name='星标', default=False)

    creator = models.ForeignKey('UserInfo', verbose_name='创建者')

    join_count = models.IntegerField(verbose_name='参与人数', default=1)
    create_datetime = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)

    class Meta:
        unique_together = ['name', 'creator']


# 项目参与者
class ProjectUser(models.Model):

    project = models.ForeignKey('Project', verbose_name='项目')
    user = models.ForeignKey('UserInfo', verbose_name='参与者')
    star = models.BooleanField(verbose_name='星标', default=False)

    create_datetime = models.DateTimeField(verbose_name='加入时间', auto_now_add=True)


# wiki表
class Wiki(models.Model):
    title = models.CharField(max_length=32,verbose_name='标题')
    content = models.TextField(verbose_name='内容')
    project = models.ForeignKey('Project', verbose_name='项目')
    # 自关联
    parent = models.ForeignKey('Wiki', null=True, blank=True, related_name='children', verbose_name='父文章')

    depth = models.IntegerField(verbose_name='深度', default=1)

    # parent = models.ForeignKey('self', )


    def __str__(self):
        return self.title




